#!/bin/bash

# Locust压测环境部署脚本
# 用于在目标服务器上快速部署测试环境

echo "=== Locust压测环境部署脚本 ==="
echo

# 检查Python环境
echo "1. 检查Python环境..."
if ! command -v python3 &> /dev/null; then
    echo "错误: Python3未安装"
    exit 1
fi
echo "✓ Python3已安装: $(python3 --version)"

# 检查pip
if ! command -v pip3 &> /dev/null; then
    echo "错误: pip3未安装"
    exit 1
fi
echo "✓ pip3已安装"

# 安装依赖
echo
echo "2. 安装Python依赖..."
if [ -f "requirements.txt" ]; then
    pip3 install -r requirements.txt
    echo "✓ 依赖安装完成"
else
    echo "安装Locust..."
    pip3 install locust
    echo "✓ Locust安装完成"
fi

# 设置脚本执行权限
echo
echo "3. 设置脚本权限..."
chmod +x start_master.sh
chmod +x start_worker.sh
echo "✓ 脚本权限设置完成"

# 检查防火墙端口
echo
echo "4. 重要提醒:"
echo "   - 确保防火墙开放端口 8089 (Web UI)"
echo "   - 确保防火墙开放端口 5557 (Master-Worker通信)"
echo "   - 确保目标服务端口 80 可访问"
echo
echo "5. 部署完成！"
echo
echo "使用方法:"
echo "  Master节点: ./start_master.sh"
echo "  Worker节点: ./start_worker.sh <目标IP>"
echo
echo "Web UI访问: http://21.124.219.93:8089"